// pages/filmreview/filmreview.js
//获取应用实例
const app = getApp()
var base64 = require('../../base/base64.js')
var util = require('../../utils/util.js')
var showVideoList
var pageNum=1
var pageSize=10
Page({

  /**
   * 页面的初始数据
   */
  data: {
    liveVideoList:[],
    isNoMore:false,
    isShowLoadBottom:false,
    loadMoreStr:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    util.netWorkUtil('film/list', {
      pageNum: pageNum,
      pageSize: pageSize
      }, function (err, res) {
        that.setData({
          loadMoreStr: "上拉加载更多......",
          liveVideoList:res.data.data,
          str:res.data,
        })
    });
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    pageNum=1;
    var that = this;
    that.setData({
      loadMoreStr: "上拉加载更多......",
    }),
    util.netWorkUtil('film/list', {
      pageNum: pageNum,
      pageSize: pageSize
    }, function (err, res) {
      that.setData({
        liveVideoList: res.data.data,
        str: res.data,
      })
      wx.stopPullDownRefresh();
    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    pageNum++;
    var that = this;
    that.setData({
      loadMoreStr: "上拉加载更多......",
    }),
    util.netWorkUtil('film/list', {
      pageNum: pageNum,
      pageSize: pageSize
    }, function (err, res) {
      var newVideoList=new Array();
      if(res.data.data!=0){
      that.data.isNoMore=false;
        newVideoList = that.data.liveVideoList.concat(res.data.data);
        that.setData({
          liveVideoList: newVideoList,
          str: res.data,
        })
      }else{
        that.data.isNoMore = true;
        that.setData({
          loadMoreStr: "已加载全部",
        });
      }
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  /**
   * 点击跳转到详情
   */
  onItemClick: function(e) {
    var that = this
    //拿到点击的index下标
    var index = parseInt(e.currentTarget.dataset.index)

    var mode = that.data.liveVideoList[index]
    // 转成json 字符串
    var modeStr = JSON.stringify(mode)
    // base64 encode
    var mode64 = base64.encode(modeStr)
    // url encode
    var modeEncode = encodeURIComponent(mode64)
    wx.navigateTo({
      url: "../playvideo/playvideo?liveVideo=" + modeEncode
    })

  },
  /**
   * 获取网络数据
   */

})